library(maptools)
library(rgdal)
require(sp)
require(rgdal)
require(maps)
library(raster)
map<-readOGR("TM_WORLD_BORDERS-0.3.shp")
plot(map)

data<-read.csv("HCED Data.csv",stringsAsFactors=F)
data<-data[!is.na(data$ID),]
data<-data[!is.na(data$Latitude),]
data$Latitude<-as.numeric(as.character(data$Latitude))
data$Longitude<-as.numeric(as.character(data$Longitude))

coordinates(data)<-c("Longitude","Latitude")
proj4string(data)<-proj4string(map)


png("Battles Map.png",width=650,height=450)
plot(coordinates(data),type="n",main="Battle Coordinates on World Map")
plot(map,border="black",add=TRUE)
points(data, pch=2, cex=.1,col="red")
dev.off()

install.packages("remotes")
remotes::install_version("SDMTools", "1.1-221")

pop1500AD<-raster("C:/Users/u5390570/Desktop/JCR Resubmission/HYDE Files/popd_1500AD.asc")

image(pop1500AD)


minimum<-min(values(pop1500AD)[values(pop1500AD)>0],na.rm=T)
mean<-mean(values(pop1500AD)[values(pop1500AD)>0],na.rm=T)
cuts<-quantile(pop1500AD,probs=seq(0,1,.1))[5:11]
colors<-colorRampPalette(c("white","red"))(length(cuts))
png("Population Density.png")
plot(pop1500AD,main="Population Density in 1500AD",breaks=cuts,col=colors,colNA="gray",legend=FALSE)
legend("bottomleft",legend=as.character(round(cuts,1)),fill=colors,cex=.65,title="People per km2 1500AD")
dev.off()

